// pages/login/login.js
import {verification} from "../../utils/verification"
import {login} from "../../utils/login"
Page({ 

  /**
   * 页面的初始数据
   */
  data: {
    email:"",
    password:"",
    emailText:"",
    passwordText:""
  },
  inputUsername(e){
    this.setData({
      email:e.detail.value
    })
    if(!this.data.email.trim()){
      this.setData({
        emailText:"邮箱不能为空"
      })
    }else if(!verification.checkEmial(this.data.email.trim())){
      this.setData({
        emailText:"邮箱格式不正确"
      })
    }
  },
  inputPassword(e){
    this.setData({
      password:e.detail.value
    })
    if(this.data.password.trim() == ""){
      this.setData({
        passwordText:"密码不能为空"
      })
    }else if(!verification.checkPassword(this.data.password.trim(),6)){
      this.setData({
        passwordText:"密码最少为6位"
      })
    }
  },
  btnClick(){
    // console.log("1111");
    // console.log(verification.checkEmial(this.data.email.trim()));
    // console.log(verification.checkPassword(this.data.password.trim(),6));
    
    
    if(verification.checkPassword(this.data.password.trim(),6) && verification.checkEmial(this.data.email.trim())){
      this.setData({
        emailText:"",
        passwordText:""
      })
      let data = {email:this.data.email,password:this.data.password}
      login(data)
      // getLogin({email:this.data.email,password:this.data.password}).then(res => {
      //   // console.log(res);
      //   wx.setStorageSync('access_token', res.access_token)
      //   getUser().then(res => {
      //     // console.log(res);
      //     wx.setStorageSync('userInfo', res)
      //     // let path = "/" + getCurrentPages().pop().route
      //     let path = wx.getStorageSync('path')
      //     console.log(path);
      //     Toast({
      //       message: '登录成功',
      //       type: 'success',
      //       onClose: () => {
      //         wx.reLaunch({
      //           url: path
      //         })
      //       }
      //     });
          
      //   })
      // }).catch(err => {
      //   console.log(err);
      // })
    }
  },

})